﻿#include "GameLayer.h"
#include "SceneFactory.h"
#include "Game.h"

GameLayer::GameLayer()
{
}

GameLayer::~GameLayer()
{
}

bool GameLayer::init()
{
	if (!Layer::init()) {
        return false;
    }
    _visibleSize = Director::getInstance()->getVisibleSize();
    _origin = Director::getInstance()->getVisibleOrigin();
    return initUIControl(_visibleSize, _origin);
}

void GameLayer::touchDown(Ref* pSender, Control::EventType event)
{
    TransitionRotoZoom* translateScene = TransitionRotoZoom::create(3.0f, SceneFactory::createSchool());
    Director::getInstance()->replaceScene(translateScene);
}

bool GameLayer::initUIControl(const Size& visibleSize, const Vec2& origin)
{
    auto schoolButton = ControlButton::create(Game::queryString("school_btn_name"), "Arial", 24);
    schoolButton->addTargetWithActionForControlEvents(this,
        cccontrol_selector(GameLayer::touchDown),
        Control::EventType::TOUCH_UP_INSIDE);
    schoolButton->setPosition(Vec2(origin.x + visibleSize.width/2,
        origin.y + visibleSize.height - schoolButton->getContentSize().height));
    this->addChild(schoolButton, 0, "schoolButton");
    return true;
}